
#This script produces Figure 4 in the main text

setwd("/Users/bsjjones/Dropbox/JoestenJones/PB R&R")

library(foreign)
library(rmeta)
library(plotrix)
#This file produces interpretation plots for the individual-level regression
#models.  The relevant Stata do file is "cues_micromodels.do". 





##########################
#Regression Plots for Micro Data
##########################
pdf("figure4_RplotALT.pdf", width=7, height=7)
par(mfrow=c(2,3),oma=c(0,0,2,0))
par(mar=c(3, 3, 2, 2))
#par(mar=c(2, 4, 1, 1))


a7nd<-read.dta("disthisp7.dta")
attach(a7nd)
coef.vec<-pr1
se.vec<-se
x.axis<-c(length(coef.vec):1)
#var.names<-label
emph<-seq(-.1, .7, .05)

a7nnd<-read.dta("disthisp1.dta")
attach(a7nnd)
coef.vec2<-pr1
se.vec2<-se
x.axis2<-c(length(coef.vec):1)
#var.names<-label
emph2<-seq(-.1, .7, .05)

plotCI(emph, coef.vec, 1.96*se.vec,  1.96*se.vec, lwd = 1, col = "black", scol = "black", lty=1, axes = TRUE, xlab = "District Hispanic", ylab = "Response Probability", pch = 20, cex.axis = .65, main = "A. District Hispanic", cex.main=.95, cex.lab=.85, mgp=c(2,.7,0), ylim=c(0,1))
lines(emph, coef.vec, type="l", col="black")
#text(0.5, .5, "Force to Return", col="black", cex=.65)
#text(.1, .01, "Path-to-Citizenship", col="gray50", cex=.65)
abline(h=.5, lty=2)

 
par(new=TRUE)

plotCI(emph2, coef.vec2, 1.96*se.vec2,  1.96*se.vec2, lwd = 1, col = "gray50", scol = "gray50", ylim=c(0,1), ylab="", xlab="", pch= 20, axes=F)
lines(emph2, coef.vec2, type="l", col="gray50")


legend("topleft", c("Force to Return", "Path-to-Citizenship"), lty=c(1,1), lwd=c(1,1), col=c("black", "gray50"), bty="n", cex=.65)


rm(list=ls())
detach(a7nd)
detach(a7ndd)

#######CHANGE IN DISTRICT HISPANIC#############

a7nd<-read.dta("hispchange7.dta")
attach(a7nd)
coef.vec<-pr1
se.vec<-se
x.axis<-c(length(coef.vec):1)
#var.names<-label
emph<-seq(-.4, .4, .05)

a7nnd<-read.dta("hispchange1.dta")
attach(a7nnd)
coef.vec2<-pr1
se.vec2<-se
x.axis2<-c(length(coef.vec):1)
#var.names<-label
emph2<-seq(-.4, .4, .05)

plotCI(emph, coef.vec, 1.96*se.vec,  1.96*se.vec, lwd = 1, col = "black",
scol = "black", lty=1, axes = TRUE, xlab = "Change in District Hispanic", ylab = "Response Probability", pch = 20, cex.axis = .65, main = "B. Change in Dist. Hispanic", cex.main=.95, cex.lab=.85, mgp=c(2,.7,0), ylim=c(0,1))
lines(emph, coef.vec, type="l", col="black")
#text(-.2, .45, "Force to Return", col="black", cex=.65)
#text(-.2, .03, "Path-to-Citizenship", col="gray50", cex=.65)
abline(h=.5, lty=2)

 
par(new=TRUE)

plotCI(emph2, coef.vec2, 1.96*se.vec2,  1.96*se.vec2, lwd = 1, col = "gray50", scol = "gray50", ylim=c(0,1), ylab="", xlab="", pch= 20, axes=F)
lines(emph2, coef.vec2, type="l", col="gray50")


legend("topleft", c("Force to Return", "Path-to-Citizenship"), lty=c(1,1), lwd=c(1,1), col=c("black", "gray50"), bty="n", cex=.65)


rm(list=ls())
detach(a7nd)
detach(a7ndd)





##################MORAL TRADITIONALISM################


morals7<-read.dta("morals7.dta")
attach(morals7)
coef.vec<-pr1
se.vec<-se
x.axis<-c(length(coef.vec):1)
#var.names<-label
emph<-seq(0, 1, .0625)

morals1<-read.dta("morals1.dta")
attach(morals1)
coef.vec2<-pr1
se.vec2<-se
x.axis2<-c(length(coef.vec):1)
#var.names<-label
emph2<-seq(0,1, .0625)



plotCI(emph, coef.vec, 1.96*se.vec,  1.96*se.vec, lwd = 1, col = "black", scol = "black", lty=1, axes = TRUE, xlab = "Moral Traditionalism", ylab = "Response Probability", pch = 20, cex.axis = .65, main = "C. Moral Traditionalism", cex.main=.95, cex.lab=.85, mgp=c(2,.7,0), ylim=c(0,1))
lines(emph, coef.vec, type="l", col="black")
#text(.35, .4, "Force to Return", col="black", cex=.65)
#text(.4, .01, "Path-to-Citizenship", col="gray50", cex=.65)
abline(h=.5, lty=2)


par(new=TRUE)

plotCI(emph2, coef.vec2, 1.96*se.vec2,  1.96*se.vec2, lwd = 1, col = "gray50", scol = "gray50", ylim=c(0,1), ylab="", xlab="", pch= 20, axes=F)
lines(emph2, coef.vec2, type="l", col="gray50")


legend("topleft", c("Force to Return", "Path-to-Citizenship"), lty=c(1,1), lwd=c(1,1), col=c("black", "gray50"), bty="n", cex=.65)


rm(list=ls())
detach(morals1)
detach(morals7)

##############CHURCH#######################

a7nd<-read.dta("church7.dta")
attach(a7nd)
coef.vec<-pr1
se.vec<-se
x.axis<-c(length(coef.vec):1)
#var.names<-label
emph<-seq(0, 1, .5)

a7nnd<-read.dta("church1.dta")
attach(a7nnd)
coef.vec2<-pr1
se.vec2<-se
x.axis2<-c(length(coef.vec):1)
#var.names<-label
emph2<-seq(0, 1, .5)

plotCI(emph, coef.vec, 1.96*se.vec,  1.96*se.vec, lwd = 1, col = "black", scol = "black", lty=1, axes = TRUE, xlab = "Church Attendance", ylab = "Response Probability", pch = 20, cex.axis = .65, main = "D. Church Attendance", cex.main=.95, cex.lab=.85, mgp=c(2,.7,0), ylim=c(0,1))
lines(emph, coef.vec, type="l", col="black")
#text(.25, .45, "Force to Return", col="black", cex=.65)
#text(.25, .01, "Path-to-Citizenship", col="gray50", cex=.65)
abline(h=.5, lty=2)

 
par(new=TRUE)

plotCI(emph2, coef.vec2, 1.96*se.vec2,  1.96*se.vec2, lwd = 1, col = "gray50", scol = "gray50", ylim=c(0,1), ylab="", xlab="", pch= 20, axes=F)
lines(emph2, coef.vec2, type="l", col="gray50")


legend("topleft", c("Force to Return", "Path-to-Citizenship"), lty=c(1,1), lwd=c(1,1), col=c("black", "gray50"), bty="n", cex=.65)


rm(list=ls())
detach(a7nd)
detach(a7ndd)


##############RETRO ECON#######################

a7nd<-read.dta("retro7.dta")
attach(a7nd)
coef.vec<-pr1
se.vec<-se
x.axis<-c(length(coef.vec):1)
#var.names<-label
emph<-seq(0, 1, .25)

a7nnd<-read.dta("retro1.dta")
attach(a7nnd)
coef.vec2<-pr1
se.vec2<-se
x.axis2<-c(length(coef.vec):1)
#var.names<-label
emph2<-seq(0, 1, .25)

plotCI(emph, coef.vec, 1.96*se.vec,  1.96*se.vec, lwd = 1, col = "black", scol = "black", lty=1, axes = TRUE, xlab = "Retrospective Evaluation", ylab = "Response Probability", pch = 20, cex.axis = .65, 
main = "E. Economic Evaluation", cex.main=.95, cex.lab=.85, mgp=c(2,.7,0), ylim=c(0,1))
lines(emph, coef.vec, type="l", col="black")
#text(.2, .4, "Force to Return", col="black", cex=.65)
#text(.2, .05, "Path-to-Citizenship", col="gray50", cex=.65)
abline(h=.5, lty=2)

 
par(new=TRUE)

plotCI(emph2, coef.vec2, 1.96*se.vec2,  1.96*se.vec2, lwd = 1, col = "gray50", scol = "gray50", ylim=c(0,1), ylab="", xlab="", pch= 20, axes=F)
lines(emph2, coef.vec2, type="l", col="gray50")


legend("topleft", c("Force to Return", "Path-to-Citizenship"), lty=c(1,1), lwd=c(1,1), col=c("black", "gray50"), bty="n", cex=.65)


rm(list=ls())
detach(a7nd)
detach(a7ndd)








##############UNEMPLOYMENT#######################

a7nd<-read.dta("unemp7.dta")
attach(a7nd)
coef.vec<-pr1
se.vec<-se
x.axis<-c(length(coef.vec):1)
#var.names<-label
emph<-seq(3, 13, .5)

a7nnd<-read.dta("unemp1.dta")
attach(a7nnd)
coef.vec2<-pr1
se.vec2<-se
x.axis2<-c(length(coef.vec):1)
#var.names<-label
emph2<-seq(3, 13, .5)

plotCI(emph, coef.vec, 1.96*se.vec,  1.96*se.vec, lwd = 1, col = "black", scol = "black", lty=1, axes = TRUE, xlab = "District Unemployment", ylab = "Response Probability", pch = 20, cex.axis = .65, main = "F. District Unemployment", cex.main=.95, cex.lab=.85, mgp=c(2,.7,0), ylim=c(0,1))
lines(emph, coef.vec, type="l", col="black")
#text(4.3, .45, "Force to Return", col="black", cex=.65)
#text(5, .03, "Path-to-Citizenship", col="gray50", cex=.65)
abline(h=.5, lty=2)

 
par(new=TRUE)

plotCI(emph2, coef.vec2, 1.96*se.vec2,  1.96*se.vec2, lwd = 1, col = "gray50", scol = "gray50", ylim=c(0,1), ylab="", xlab="", pch= 20, axes=F)
lines(emph2, coef.vec2, type="l", col="gray50")


legend("topleft", c("Force to Return", "Path-to-Citizenship"), lty=c(1,1), lwd=c(1,1), col=c("black", "gray50"), bty="n", cex=.65)
title("Immigration Opinion as a Function of District-Level Factors and Moral Traditionalism", outer=TRUE)



rm(list=ls())
detach(a7nd)
detach(a7ndd)

dev.off()


